Vue.filter('dateFormat',function (value){
    const date = new Date(value)
    const year = date.getFullYear();
    const month = date.getMonth()+1
    const day = date.getDay()
    const hours = date.getHours()
    const minutes = date.getMinutes()
    const seconds = date.getSeconds()
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
})
new Vue({
    el:"#app",
    data:{
        adds:{id:"id",name:"图书名称",press:"出版社",author:"作者"},
        th:["序号","图书名称","出版社","作者","时间"],
        tbody_tr:[
            {visible:true,id:1,name:"Web前端开发技术",press:"清华大学出版社",author:"储久良",date:"2023-10-9 10:17:14",inEdit:false},
            {visible:true,id:2,name:"Java程序设计",press:"电子工业出版社",author:"耿祥义",date:"2023-10-9 10:17:14",inEdit:false},
            {visible:true,id:3,name:"JavaScript高级程序设计",press:"高等教育出版社",author:"张路路",date:"2023-10-9 10:17:14",inEdit:false},
        ],
        addsSet:{id:"",name:"",press:"",author:""},
        tableInEdit:false,
        searchName:''
    },
    methods:{
        addF(){
            for (var i in this.addsSet){
                if (this.addsSet[i]===''||this.addsSet[i]===" "){
                    alert(this.adds[i]+"不能为空")
                    return
                }
            }
            var set = {id:"",name:"",press:"",author:"",date:""}
            for (i in this.addsSet){
                set[i] = this.addsSet[i]
            }
            set.date = new Date()
            this.$set(this.tbody_tr,this.tbody_tr.length,set)
        },
        deleteBook(index){
            this.tbody_tr.splice(index,1)
        },
        editF(index){
            this.tbody_tr[index].inEdit = this.tableInEdit = true
        },
        saveF(index) {
            this.tbody_tr[index].inEdit = this.tableInEdit = false
        },
        search(name){
            const regex =name===''?/./:eval("/"+name+"/")
            for (var i in this.tbody_tr)
                this.tbody_tr[i].visible = regex.test((this.tbody_tr[i].name))
        }
    }
})